import Vue from "vue"
import Vuex from "vuex"
import { INCREMENT, } from "./mutations-types"

// 1.安装vuex插件
Vue.use(Vuex)

// 抽离模块
import moduleA from "./moudles/moduleA"

// 2.创建对象

const state = {
    // 定义状态
    count: 0,
    students: [
        { id: 100, name: 'cgs', age: 18 },
        { id: 101, name: 'cgs1', age: 19 },
        { id: 102, name: 'cgs2', age: 20 },
    ],
    info: {
        name: 'cgsthtm',
        age: 1,
        sex: 'male',
        height: 163, // 此属性，为了测试mutations中的异步操作，为了验证mutations中异步操作不能实际修改state中管理的状态，而只是单纯的响应式显示
        level: 1 // 此属性，为了测试actions中调用异步操作
    }
}

import mutations from "./mutations"
import actions from "./actions"
import getters from "./getters"

const store = new Vuex.Store({
    state: state,
    mutations: mutations,
    actions: actions,
    getters: getters,
    modules: {
        a: moduleA,
        b: {
            state: {

            },
            mutations: {

            },
            getters: {

            },
            actions: {

            }
        }
    }
})

// 3.导出对象
export default store

// 对象的解构
const obj = {
    name: 'cgs',
    age: 18,
    sex: 'male',
    address: 'Qinhuangdao'
}
const { name, sex, age } = obj
console.log(name)
console.log(sex)
console.log(age)